

import 'package:xim/common/get_style_view.dart';
import 'package:xim/config/store_config.dart';
import 'package:xim/http/apis/user/user_api.dart';
import 'package:xim/http/apis/user/user_model.dart';
import 'package:xim/http/http.dart';

class ProfilePublicController extends GetxStateMixinController<void>{

  final String userAccount;

  ProfilePublicController(this.userAccount);

  late final UserInfoModel userInfo;

  bool isFriend = false;

  late final bool isSelf;

  /// 当前用户信息
  late final UserInfoModel selfInfo;

  /// 好友用户信息
  UserFriendModel? friendModel;

  @override
  Future<void> dataInit() async {
    userInfo = await UserApi.queryUserInfo(account: userAccount);
    selfInfo = await UserApi.queryUserInfo();
    isSelf = selfInfo.account == userInfo.account;
    var friends = await UserApi.queryFriends(status: null);
    if(friends.isEmpty){
      isFriend = false;
    }else{
      for(var u in friends){
        if(u.friendUserInfo.account==userAccount){
          isFriend = true;
          friendModel = u;
          break;
        }
      }
    }
  }

  /// 删除该好友
  Future<ResponseResult> deleteFriend() async {
    return UserApi.deleteFriend(userAccount);
  }

  String get source {
    if(friendModel==null) {
      return '';
    }
    if(friendModel!.applySourceType==null){
      return '未知';
    }
    if(friendModel!.applySourceType==1){
      return '二维码';
    }
    if(friendModel!.applySourceType==2){
      return '搜索';
    }
    return '未知';
  }

  String get attachMessage {
    if(friendModel==null) {
      return '';
    }
    if(friendModel!.applyNote==null){
      return '';
    }
    return friendModel!.applyNote!;
  }

}